利用するデータ

Covid19

Covid19 Japanの公開データ。

都道府県

都道府県と地方区分に関するデータは自作データ。

サマライズ

df %>% 
  skimr::skim()
Data summary
Name Piped data
Number of rows 87435
Number of columns 23
_______________________
Column type frequency:
character 19
logical 3
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
patientId 0 1.00 1 8 0 86028 0
dateAnnounced 0 1.00 10 10 0 251 0
gender 9503 0.89 1 1 0 2 0
detectedPrefecture 0 1.00 3 15 0 49 0
patientStatus 83666 0.04 8 23 0 8 0
notes 45594 0.48 1 270 0 39211 1
mhlwPatientNumber 86986 0.01 1 11 0 434 0
prefecturePatientNumber 8064 0.91 5 20 0 79362 0
prefectureSourceURL 56236 0.36 5 224 0 3424 0
residence 17322 0.80 1 38 0 1406 0
sourceURL 586 0.99 1 239 0 7037 0
relatedPatients 78292 0.10 2 259 0 5596 0
knownCluster 85123 0.03 3 88 0 222 0
detectedCityTown 65066 0.26 2 22 0 660 0
cityPrefectureNumber 65100 0.26 1 34 0 22326 2
citySourceURL 75707 0.13 9 317 0 3592 0
deceasedDate 85825 0.02 10 10 0 201 0
deceasedReportedDate 86335 0.01 10 10 0 175 0
deathSourceURL 86429 0.01 14 123 0 618 0

Variable type: logical

skim_variable n_missing complete_rate mean count
confirmedPatient 0 1 0.98 TRU: 86027, FAL: 1408
charterFlightPassenger 87421 0 1.00 TRU: 14
cruisePassengerDisembarked 87424 0 1.00 TRU: 11

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
ageBracket 0 1 33.62 23.13 -1 20 30 50 100 ▃▇▅▂▁

ラングリング

必要と思われる変量(フィーチャー)のみを適切な形式に変換し、地域区分でも分析できるように都道府県データと結合。

x <- df %>% 
  dplyr::mutate(dateAnnounced = lubridate::as_date(dateAnnounced),
                ageBracket = forcats::as_factor(ageBracket),
                gender = forcats::as_factor(gender),
                patientStatus = forcats::as_factor(patientStatus),
                residence = forcats::as_factor(residence),
                cluster = dplyr::if_else(!is.na(knownCluster), TRUE, FALSE)) %>% 
  dplyr::select(dateAnnounced, ageBracket, gender, detectedPrefecture,
                patientStatus, knownCluster, cluster) %>% 
  dplyr::left_join(prefs, by = c("detectedPrefecture" = "pref"))

x
x %>% 
  skimr::skim()
Data summary
Name Piped data
Number of rows 87435
Number of columns 13
_______________________
Column type frequency:
character 7
Date 1
factor 4
logical 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
detectedPrefecture 0 1.00 3 15 0 49 0
knownCluster 85123 0.03 3 88 0 222 0
pcode 1018 0.99 2 2 0 47 0
都道府県 1018 0.99 3 4 0 47 0
八地方区分 1018 0.99 4 5 0 8 0
広域圏 6014 0.93 3 3 0 8 0
通俗的区分 1018 0.99 2 3 0 11 0

Variable type: Date

skim_variable n_missing complete_rate min max median n_unique
dateAnnounced 0 1 2020-01-15 2020-10-05 2020-08-06 251

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
ageBracket 0 1.00 FALSE 13 20: 21750, 30: 13443, 40: 10914, -1: 9579
gender 9503 0.89 FALSE 2 M: 43926, F: 34006
patientStatus 83666 0.04 FALSE 8 Dec: 1600, Hos: 1266, Hom: 316, Dis: 283
fct_pref 1018 0.99 FALSE 47 Tok: 27010, Osa: 10866, Kan: 7229, Aic: 5531

Variable type: logical

skim_variable n_missing complete_rate mean count
cluster 0 1 0.03 FAL: 85123, TRU: 2312

可視化

全体傾向

date <- x %>% 
  with(seq(range(dateAnnounced)[1], range(dateAnnounced)[2], by = "day")) %>% 
  as.data.frame() %>% 
  dplyr::rename(date = 1)

sec_scale <- 50

x %>% 
  dplyr::group_by(dateAnnounced) %>% 
  dplyr::summarise(n = n()) %>% 
  dplyr::left_join(date, ., by = c("date" = "dateAnnounced")) %>% 
  dplyr::mutate(n = ifelse(is.na(n), 0, n)) %>% 
  dplyr::mutate(cum = cumsum(n),
                ma = zoo::rollmeanr(n, k = 7L, na.pad = TRUE)) %>%
  print() %>% 
  ggplot2::ggplot(ggplot2::aes(x = date)) + 
    ggplot2::geom_bar(ggplot2::aes(y = n), stat = "identity",
                      fill = "dark green", alpha = 0.5) + 
    ggplot2::geom_line(ggplot2::aes(y = cum / sec_scale), colour = "dark green") +
    ggplot2::geom_line(ggplot2::aes(y = ma), colour = "dark red") + 
    ggplot2::scale_y_continuous(
      name = "陽性確定数(日別)・7日間移動平均(濃赤折線)",
      sec.axis = ggplot2::sec_axis(~ . * sec_scale,
                                    name = "累積陽性確定数(折線)")
    ) +
    ggplot2::labs(title = paste0("Covid19, Japan(@", Sys.time(), ")"),
                  subtitle = "", x = "日付")
## `summarise()` ungrouping output (override with `.groups` argument)
##           date    n   cum           ma
## 1   2020-01-15    1     1           NA
## 2   2020-01-16    0     1           NA
## 3   2020-01-17    0     1           NA
## 4   2020-01-18    0     1           NA
## 5   2020-01-19    0     1           NA
## 6   2020-01-20    0     1           NA
## 7   2020-01-21    0     1    0.1428571
## 8   2020-01-22    0     1    0.0000000
## 9   2020-01-23    0     1    0.0000000
## 10  2020-01-24    1     2    0.1428571
## 11  2020-01-25    1     3    0.2857143
## 12  2020-01-26    1     4    0.4285714
## 13  2020-01-27    0     4    0.4285714
## 14  2020-01-28    3     7    0.8571429
## 15  2020-01-29    1     8    1.0000000
## 16  2020-01-30    5    13    1.7142857
## 17  2020-01-31    1    14    1.7142857
## 18  2020-02-01    4    18    2.1428571
## 19  2020-02-02    0    18    2.0000000
## 20  2020-02-03    0    18    2.0000000
## 21  2020-02-04    2    20    1.8571429
## 22  2020-02-05    3    23    2.1428571
## 23  2020-02-06    0    23    1.4285714
## 24  2020-02-07    0    23    1.2857143
## 25  2020-02-08    1    24    0.8571429
## 26  2020-02-09    0    24    0.8571429
## 27  2020-02-10    2    26    1.1428571
## 28  2020-02-11    1    27    1.0000000
## 29  2020-02-12    1    28    0.7142857
## 30  2020-02-13    5    33    1.4285714
## 31  2020-02-14   10    43    2.8571429
## 32  2020-02-15   11    54    4.2857143
## 33  2020-02-16    6    60    5.1428571
## 34  2020-02-17    7    67    5.8571429
## 35  2020-02-18   12    79    7.4285714
## 36  2020-02-19    6    85    8.1428571
## 37  2020-02-20   10    95    8.8571429
## 38  2020-02-21   17   112    9.8571429
## 39  2020-02-22   25   137   11.8571429
## 40  2020-02-23   12   149   12.7142857
## 41  2020-02-24   11   160   13.2857143
## 42  2020-02-25   13   173   13.4285714
## 43  2020-02-26   19   192   15.2857143
## 44  2020-02-27   26   218   17.5714286
## 45  2020-02-28   18   236   17.7142857
## 46  2020-02-29    9   245   15.4285714
## 47  2020-03-01   14   259   15.7142857
## 48  2020-03-02   19   278   16.8571429
## 49  2020-03-03   20   298   17.8571429
## 50  2020-03-04   35   333   20.1428571
## 51  2020-03-05   32   365   21.0000000
## 52  2020-03-06   55   420   26.2857143
## 53  2020-03-07   46   466   31.5714286
## 54  2020-03-08   33   499   34.2857143
## 55  2020-03-09   28   527   35.5714286
## 56  2020-03-10   59   586   41.1428571
## 57  2020-03-11   56   642   44.1428571
## 58  2020-03-12   56   698   47.5714286
## 59  2020-03-13   38   736   45.1428571
## 60  2020-03-14   63   799   47.5714286
## 61  2020-03-15   32   831   47.4285714
## 62  2020-03-16   19   850   46.1428571
## 63  2020-03-17   50   900   44.8571429
## 64  2020-03-18   35   935   41.8571429
## 65  2020-03-19   40   975   39.5714286
## 66  2020-03-20   55  1030   42.0000000
## 67  2020-03-21   37  1067   38.2857143
## 68  2020-03-22   46  1113   40.2857143
## 69  2020-03-23   40  1153   43.2857143
## 70  2020-03-24   73  1226   46.5714286
## 71  2020-03-25   98  1324   55.5714286
## 72  2020-03-26  105  1429   64.8571429
## 73  2020-03-27  114  1543   73.2857143
## 74  2020-03-28  204  1747   97.1428571
## 75  2020-03-29  181  1928  116.4285714
## 76  2020-03-30   95  2023  124.2857143
## 77  2020-03-31  257  2280  150.5714286
## 78  2020-04-01  284  2564  177.1428571
## 79  2020-04-02  285  2849  202.8571429
## 80  2020-04-03  340  3189  235.1428571
## 81  2020-04-04  377  3566  259.8571429
## 82  2020-04-05  364  3930  286.0000000
## 83  2020-04-06  238  4168  306.4285714
## 84  2020-04-07  378  4546  323.7142857
## 85  2020-04-08  541  5087  360.4285714
## 86  2020-04-09  596  5683  404.8571429
## 87  2020-04-10  646  6329  448.5714286
## 88  2020-04-11  708  7037  495.8571429
## 89  2020-04-12  529  7566  519.4285714
## 90  2020-04-13  305  7871  529.0000000
## 91  2020-04-14  526  8397  550.1428571
## 92  2020-04-15  574  8971  554.8571429
## 93  2020-04-16  575  9546  551.8571429
## 94  2020-04-17  574 10120  541.5714286
## 95  2020-04-18  607 10727  527.1428571
## 96  2020-04-19  381 11108  506.0000000
## 97  2020-04-20  363 11471  514.2857143
## 98  2020-04-21  396 11867  495.7142857
## 99  2020-04-22  415 12282  473.0000000
## 100 2020-04-23  455 12737  455.8571429
## 101 2020-04-24  399 13136  430.8571429
## 102 2020-04-25  350 13486  394.1428571
## 103 2020-04-26  227 13713  372.1428571
## 104 2020-04-27  194 13907  348.0000000
## 105 2020-04-28  298 14205  334.0000000
## 106 2020-04-29  229 14434  307.4285714
## 107 2020-04-30  226 14660  274.7142857
## 108 2020-05-01  298 14958  260.2857143
## 109 2020-05-02  330 15288  257.4285714
## 110 2020-05-03  213 15501  255.4285714
## 111 2020-05-04  187 15688  254.4285714
## 112 2020-05-05  132 15820  230.7142857
## 113 2020-05-06  111 15931  213.8571429
## 114 2020-05-07  108 16039  197.0000000
## 115 2020-05-08  102 16141  169.0000000
## 116 2020-05-09  129 16270  140.2857143
## 117 2020-05-10   77 16347  120.8571429
## 118 2020-05-11   59 16406  102.5714286
## 119 2020-05-12  104 16510   98.5714286
## 120 2020-05-13   66 16576   92.1428571
## 121 2020-05-14  112 16688   92.7142857
## 122 2020-05-15   65 16753   87.4285714
## 123 2020-05-16   69 16822   78.8571429
## 124 2020-05-17   35 16857   72.8571429
## 125 2020-05-18   42 16899   70.4285714
## 126 2020-05-19   32 16931   60.1428571
## 127 2020-05-20   40 16971   56.4285714
## 128 2020-05-21   55 17026   48.2857143
## 129 2020-05-22   36 17062   44.1428571
## 130 2020-05-23   35 17097   39.2857143
## 131 2020-05-24   55 17152   42.1428571
## 132 2020-05-25   34 17186   41.0000000
## 133 2020-05-26   36 17222   41.5714286
## 134 2020-05-27   42 17264   41.8571429
## 135 2020-05-28   71 17335   44.1428571
## 136 2020-05-29   80 17415   50.4285714
## 137 2020-05-30   50 17465   52.5714286
## 138 2020-05-31   37 17502   50.0000000
## 139 2020-06-01   38 17540   50.5714286
## 140 2020-06-02   54 17594   53.1428571
## 141 2020-06-03   34 17628   52.0000000
## 142 2020-06-04   52 17680   49.2857143
## 143 2020-06-05   47 17727   44.5714286
## 144 2020-06-06   50 17777   44.5714286
## 145 2020-06-07   36 17813   44.4285714
## 146 2020-06-08   23 17836   42.2857143
## 147 2020-06-09   48 17884   41.4285714
## 148 2020-06-10   40 17924   42.2857143
## 149 2020-06-11   39 17963   40.4285714
## 150 2020-06-12   64 18027   42.8571429
## 151 2020-06-13   45 18072   42.1428571
## 152 2020-06-14   75 18147   47.7142857
## 153 2020-06-15   74 18221   55.0000000
## 154 2020-06-16   49 18270   55.1428571
## 155 2020-06-17   50 18320   56.5714286
## 156 2020-06-18   72 18392   61.2857143
## 157 2020-06-19   74 18466   62.7142857
## 158 2020-06-20   63 18529   65.2857143
## 159 2020-06-21   60 18589   63.1428571
## 160 2020-06-22   43 18632   58.7142857
## 161 2020-06-23   68 18700   61.4285714
## 162 2020-06-24   99 18799   68.4285714
## 163 2020-06-25   81 18880   69.7142857
## 164 2020-06-26  105 18985   74.1428571
## 165 2020-06-27   93 19078   78.4285714
## 166 2020-06-28  111 19189   85.7142857
## 167 2020-06-29  111 19300   95.4285714
## 168 2020-06-30  140 19440  105.7142857
## 169 2020-07-01  131 19571  110.2857143
## 170 2020-07-02  202 19773  127.5714286
## 171 2020-07-03  242 20015  147.1428571
## 172 2020-07-04  273 20288  172.8571429
## 173 2020-07-05  209 20497  186.8571429
## 174 2020-07-06  174 20671  195.8571429
## 175 2020-07-07  213 20884  206.2857143
## 176 2020-07-08  209 21093  217.4285714
## 177 2020-07-09  355 21448  239.2857143
## 178 2020-07-10  430 21878  266.1428571
## 179 2020-07-11  386 22264  282.2857143
## 180 2020-07-12  410 22674  311.0000000
## 181 2020-07-13  263 22937  323.7142857
## 182 2020-07-14  331 23268  340.5714286
## 183 2020-07-15  456 23724  375.8571429
## 184 2020-07-16  622 24346  414.0000000
## 185 2020-07-17  597 24943  437.8571429
## 186 2020-07-18  670 25613  478.4285714
## 187 2020-07-19  512 26125  493.0000000
## 188 2020-07-20  413 26538  514.4285714
## 189 2020-07-21  635 27173  557.8571429
## 190 2020-07-22  796 27969  606.4285714
## 191 2020-07-23  982 28951  657.8571429
## 192 2020-07-24  779 29730  683.8571429
## 193 2020-07-25  805 30535  703.1428571
## 194 2020-07-26  835 31370  749.2857143
## 195 2020-07-27  599 31969  775.8571429
## 196 2020-07-28  980 32949  825.1428571
## 197 2020-07-29 1269 34218  892.7142857
## 198 2020-07-30 1302 35520  938.4285714
## 199 2020-07-31 1586 37106 1053.7142857
## 200 2020-08-01 1535 38641 1158.0000000
## 201 2020-08-02 1332 39973 1229.0000000
## 202 2020-08-03  965 40938 1281.2857143
## 203 2020-08-04 1243 42181 1318.8571429
## 204 2020-08-05 1360 43541 1331.8571429
## 205 2020-08-06 1491 45032 1358.8571429
## 206 2020-08-07 1610 46642 1362.2857143
## 207 2020-08-08 1570 48212 1367.2857143
## 208 2020-08-09 1447 49659 1383.7142857
## 209 2020-08-10  842 50501 1366.1428571
## 210 2020-08-11  704 51205 1289.1428571
## 211 2020-08-12  984 52189 1235.4285714
## 212 2020-08-13 1183 53372 1191.4285714
## 213 2020-08-14 1363 54735 1156.1428571
## 214 2020-08-15 1240 55975 1109.0000000
## 215 2020-08-16 1032 57007 1049.7142857
## 216 2020-08-17  656 57663 1023.1428571
## 217 2020-08-18  930 58593 1055.4285714
## 218 2020-08-19 1080 59673 1069.1428571
## 219 2020-08-20 1195 60868 1070.8571429
## 220 2020-08-21 1053 61921 1026.5714286
## 221 2020-08-22  989 62910  990.7142857
## 222 2020-08-23  754 63664  951.0000000
## 223 2020-08-24  504 64168  929.2857143
## 224 2020-08-25  729 64897  900.5714286
## 225 2020-08-26  907 65804  875.8571429
## 226 2020-08-27  881 66685  831.0000000
## 227 2020-08-28  888 67573  807.4285714
## 228 2020-08-29  856 68429  788.4285714
## 229 2020-08-30  613 69042  768.2857143
## 230 2020-08-31  445 69487  759.8571429
## 231 2020-09-01  646 70133  748.0000000
## 232 2020-09-02  606 70739  705.0000000
## 233 2020-09-03  667 71406  674.4285714
## 234 2020-09-04  602 72008  633.5714286
## 235 2020-09-05  610 72618  598.4285714
## 236 2020-09-06  457 73075  576.1428571
## 237 2020-09-07  303 73378  555.8571429
## 238 2020-09-08  529 73907  539.1428571
## 239 2020-09-09  522 74429  527.1428571
## 240 2020-09-10  717 75146  534.2857143
## 241 2020-09-11  653 75799  541.5714286
## 242 2020-09-12  659 76458  548.5714286
## 243 2020-09-13  446 76904  547.0000000
## 244 2020-09-14  276 77180  543.1428571
## 245 2020-09-15  539 77719  544.5714286
## 246 2020-09-16  562 78281  550.2857143
## 247 2020-09-17  500 78781  519.2857143
## 248 2020-09-18  580 79361  508.8571429
## 249 2020-09-19  603 79964  500.8571429
## 250 2020-09-20  484 80448  506.2857143
## 251 2020-09-21  318 80766  512.2857143
## 252 2020-09-22  336 81102  483.2857143
## 253 2020-09-23  224 81326  435.0000000
## 254 2020-09-24  493 81819  434.0000000
## 255 2020-09-25  582 82401  434.2857143
## 256 2020-09-26  646 83047  440.4285714
## 257 2020-09-27  488 83535  441.0000000
## 258 2020-09-28  311 83846  440.0000000
## 259 2020-09-29  538 84384  468.8571429
## 260 2020-09-30  581 84965  519.8571429
## 261 2020-10-01  645 85610  541.5714286
## 262 2020-10-02  553 86163  537.4285714
## 263 2020-10-03  587 86750  529.0000000
## 264 2020-10-04  402 87152  516.7142857
## 265 2020-10-05  283 87435  512.7142857
## Warning: Removed 6 row(s) containing missing values (geom_path).

plotly::ggplotly()